package com.maple.controller.admin;

import com.maple.dto.CategoryDTO;
import com.maple.dto.CategoryPageQueryDTO;
import com.maple.entity.Category;
import com.maple.result.PageResult;
import com.maple.result.Result;
import com.maple.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {

    @Autowired
    CategoryService categoryService;


    @PostMapping
    public Result save(@RequestBody CategoryDTO categoryDTO){
        log.info("新增菜品分类，{}",categoryDTO);
        categoryService.save(categoryDTO);
        return Result.success();
    }


    @GetMapping("/page")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("菜品分类：{}",categoryPageQueryDTO);
        PageResult pageResult = categoryService.page(categoryPageQueryDTO);
        return Result.success(pageResult);
    }


    @GetMapping("/list")
    public Result queryByType(@RequestParam String type){
        log.info("根据菜品类型查询：{}", type);
        List<Category> list = categoryService.queryByType(type);
        return Result.success(list);
    }


    @PostMapping("/status/{status}")
    public Result changeStatus(@PathVariable String status, String id){
        log.info("菜品状态修改：{}", status);
        categoryService.changeStatus(status, id);
        return Result.success();
    }


    @PutMapping
    public Result update(@RequestBody CategoryDTO categoryDTO){
        log.info("修改菜品分类：{}", categoryDTO);
        categoryService.update(categoryDTO);
        return Result.success();
    }

    @DeleteMapping
    public Result deleteById(@RequestParam String id){
        log.info("根据id删除菜品分类：{}", id);
        categoryService.deleteById(id);
        return Result.success();
    }









}
